package com.weactivity.service.impl;

import com.weactivity.dto.FeedbackDTO;
import com.weactivity.entity.Feedback;
import com.weactivity.entity.Report;
import com.weactivity.mapper.FeedbackMapper;
import com.weactivity.mapper.ReportMapper;
import com.weactivity.service.FeedbackService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;
    @Autowired
    private ReportMapper reportMapper;

    /**
     * 提交反馈
     *
     * @param feedbackDTO
     * @return
     */
    @Override
    public void submit(FeedbackDTO feedbackDTO) {
        Feedback feedback = new Feedback();
        BeanUtils.copyProperties(feedbackDTO,feedback);
        feedback.setEvaluateA(feedbackDTO.getEvaluateA());
        feedback.setTime(LocalDateTime.now());
        feedbackMapper.insert(feedback);
    }

    /**
     * 生成活动报告
     *
     * @param aid
     * @return
     */
    @Override
    public void generate(int aid) {
        Report report = new Report();
        report.setAid(aid);
        int o_uid = feedbackMapper.findOrganByAid(aid);
        int m_uid = feedbackMapper.findManByAid(aid);
        int evaluate_a = feedbackMapper.FindEvaAByAid(aid);
        int evaluate_m = feedbackMapper.FindEvaMByAid(aid);
        int evaluate_o = feedbackMapper.FindEvaOByAid(aid);

        report.setMUid(m_uid);
        report.setOUid(o_uid);
        report.setAverEvaluateA(evaluate_a);
        report.setAverEvaluateM(evaluate_m);
        report.setAverEvaluateO(evaluate_o);
        report.setTime(LocalDateTime.now());
        reportMapper.insert(report);

    }

    /**
     * 展示活动报告
     *
     * @param aid
     * @return
     */
    @Override
    public Report show(int aid) {

        return reportMapper.findByAid(aid);

    }

    @Override
    public List<FeedbackDTO> selectByAid(int aid) {
        return feedbackMapper.SelectByAid(aid);
    }

    @Override
    public int findTotalNumByAid(int aid) {
        return feedbackMapper.findTotalNumByAid(aid);
    }

    @Override
    public int findNumByAid(int aid) {
        return feedbackMapper.findNumByAid(aid);
    }
}
